﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using GroupManager.Class;
using System.IO;
namespace GroupManager
{
    public partial class ThemThongBao : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btLuuNhap_Click(object sender, EventArgs e)
        {
            string tieude = txtTieuDe.Text.Trim();
            if (string.IsNullOrEmpty(tieude))
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Bạn phải nhập tiêu đề!');", true);
                return;
            }
            string noidung = CKEditorControl1.Text.Trim();
            if (string.IsNullOrEmpty(noidung))
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Bạn phải nhập nội dung!');", true);
                return;
            }
            string path;
            if (FileUpload1.HasFile)
            {
                string loaifile = Path.GetExtension(FileUpload1.FileName);
                path = @"~/Resource/images/image_thongbao/" + LopThongBao.MaAnh().ToString() + loaifile;
                FileUpload1.SaveAs(HttpContext.Current.Server.MapPath("" + path));
            }
            else
            {
                path = @"~/Resource/images/image_thongbao/default.png";
            }
            string mdoinhom = Request.QueryString["doinhom"];
            int madoinhom = int.Parse(mdoinhom);
            LopThongBao.ThemThongBao(tieude, noidung, madoinhom, path, false);
            btHienThi.Enabled = false;
            btLuuNhap.Enabled = false;
        }

        protected void btHienThi_Click(object sender, EventArgs e)
        {
            string tieude = txtTieuDe.Text.Trim();
            if (string.IsNullOrEmpty(tieude))
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Bạn phải nhập tiêu đề!');", true);
                return;
            }
            string noidung = CKEditorControl1.Text.Trim();
            if (string.IsNullOrEmpty(noidung))
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Bạn phải nhập nội dung!');", true);
                return;
            }
            string path;
            if (FileUpload1.HasFile)
            {
                string loaifile = Path.GetExtension(FileUpload1.FileName);
                path = @"~/Resource/images/image_thongbao/" + LopThongBao.MaAnh().ToString() + loaifile;
                FileUpload1.SaveAs(HttpContext.Current.Server.MapPath("" + path));
            }
            else
            {
                path = @"~/Resource/images/image_thongbao/default.png";
            }
            string mdoinhom = Request.QueryString["doinhom"];
            int madoinhom = int.Parse(mdoinhom);
            LopThongBao.ThemThongBao(tieude, noidung, madoinhom, path, true);
            btHienThi.Enabled = false;
            btLuuNhap.Enabled = false;
        }
    }
}